<?php

/**
 *
 * Class AuthAction
 */
import("@.ORG.Common");
import("@.ORG.Helper");
class AuthAction extends Action {

    protected function _initialize() {
        header("Content-Type:text/html; charset=utf-8");
        C('LAYOUT_ON',false);
    }

    public function index() {
        $account = isset($_POST['username']) ? $_POST['username'] : '';
        $password = isset($_POST['password']) ? $_POST['password'] : '';
        if( !empty($account) && !empty($password) ){
            $model = M("user_info");
            $data = $model->where(array('username'=>$account))->find();
            if( $data && $data['password'] == md5($password) ){
                $_SESSION['adminUserID'] = $data['id'];
                $_SESSION['adminUserName'] = $account;
                $this->redirect('/Info/index');
            }
            else{
                $this->assign('msg','用户名或密码错误');
            }
        }

        $this->display();
    }

    public function logout(){
        unset($_SESSION['userID']);
        unset($_SESSION['userInfo']);
        session_destroy();
        $this->redirect('/Auth/index');
        exit();
    }

    public function dpi(){
        $this->display();
    }
}